<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /*
        .如何指定this的值
        1.调用时候
        2.创建时候
        */

        //1.调用时候
        function fn(name, age) {
            console.log(this)
            console.log(name, age)
        }
        const person = {
            name: 'why'
        }
        //1.1call
        fn.call(person, 20, 18)
        //1.2apply ，以数组方式传参
        fn.apply(person, [2, 1])


        //2.创建时候
        //2.1bind
        const bindFn = fn.bind(person, 555)
        bindFn(666)
        //2.2箭头函数，向上级作用域找
        const arrowFn = (name, age) => {
            console.log(this)
            console.log(name, age)
        }
        arrowFn('why', 18)
    </script>
</body>

</html>